import {getPrice_gupiao, getPrice_gupiao_name} from "./gupiao_api.js";

export const getPriceGuPiao = async (id) => {
  try {
    let result = await getPrice_gupiao(id);
    let nameRes = await getPrice_gupiao_name(id);
    let data = result.data;
    let nameData = nameRes.data;
    // console.log(data.Result.cur, 'getPriceGuPiao');
    if(Number(data.ResultCode) !== 0 || Number(nameData.ResultCode) !== 0) {
      return false;
    }
    let name = nameData.Result.technologyScore.increase.items.filter(item => item.code.toString() === id.toString())[0].text;
    // console.log(`股票：${id} 名称：${name} 价格为：${data.Result.cur.price}`);
    return {
      result: true,
      name,
      price: data.Result.cur.price
    }; // 返回价格数据
  } catch (e) {
    console.log(e.message, 'getPriceGuPiao Error');
    return {
      result: false
    };
  }

};
